package com.arvato.minipro.controller.common;

import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.arvato.minipro.bean.bean_dto.common.Result;
import com.arvato.common.https.WxMiniproOwnRequestUtil;
import com.arvato.common.wx.crypt.AesException;
import com.arvato.minipro.controller.BaseController;

/**
 * 
 * @author: smallking
 * 
 * @Descibe:直接以小程序开发者的身份开发小程序功能
 * 
 * @Date: 2018年09月27日  下午5:03:05
 */
@Controller
@RequestMapping(value="/minipro/own")
public class MiniproOwnController extends BaseController{
	
	private Logger logger = LoggerFactory.getLogger(MiniproOwnController.class);
	
	@Autowired
	private WxMiniproOwnRequestUtil wxMiniproOwnRequestUtil;
	
	@ResponseBody
	@RequestMapping(value="/access_token")
	public Result getVerifyTicket(HttpServletRequest req) throws AesException {
		// 发送请求给微信 获得access_token
		Result result = wxMiniproOwnRequestUtil.getAccessToken();
		logger.error(req.getRequestURI() + ">>>>>>" + result);
		return result;
	}
	
	/**
	 * 获取小程序的QRcode
	 * @param req
	 * @param path 扫描二维码之后跳转的路径
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/qrcode")
	public Result miniproQrcode(HttpServletRequest req, String path) throws AesException {
		Result result = wxMiniproOwnRequestUtil.getQrcode(path);
		logger.error(req.getRequestURI() + ">>>>>" + "参数path：" + path + ">>>>>>" + result);
		return result;
	}
	
	/**
	 * 获取小程序的小程序码
	 * @param req
	 * @param path 扫描小程序码之后跳转的路径
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/codepng")
	public Result miniproCode(HttpServletRequest req, String path) throws AesException {
		Result result = wxMiniproOwnRequestUtil.getCodePng(path);
		logger.error(req.getRequestURI() + ">>>>>" + "参数path：" + path + ">>>>>>" + result);
		return result;
	}
}
